package com.ruoyi.project.cms.notice.service.impl;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.cms.notice.domain.CNotice;
import com.ruoyi.project.cms.notice.mapper.CNoticeMapper;
import com.ruoyi.project.cms.notice.mapper.TypeMapper;
import com.ruoyi.project.cms.notice.service.CNoticeService;
import com.ruoyi.project.system.notice.domain.Notice;
import com.ruoyi.project.system.notice.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 作者:yzc
 * 类名:CNoticeServiceImpl
 * 描述:TODO
 * 时间:2020-05-21
 */
@Service
public class CNoticeServiceImpl implements CNoticeService {

    @Autowired
    private CNoticeMapper cNoticeMapper;

    @Autowired
    private TypeMapper typeMapper;


    @Override
    public List<CNotice> findAllList(CNotice cNotice) {

        return cNoticeMapper.selectAllList(cNotice);
    }

    @Override
    public CNotice findById(Integer noticeId) {
        return cNoticeMapper.selectNotice(noticeId);
    }

    @Override
    public int addNotice(CNotice cNotice) {
        cNotice.setCreateBy(ShiroUtils.getLoginName());
        String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();
        cNotice.setCreateTime(time);
        cNotice.setBrowseNumber(0);
        return cNoticeMapper.insert(cNotice);
    }

    @Override
    public int updateNotice(CNotice cNotice) {

        return cNoticeMapper.update(cNotice);
    }

    @Override
    public int removeType(String ids) throws Exception {
        Integer i = 0;
        Long[] noticeIds = Convert.toLongArray(ids);
        for (Long noticeId : noticeIds)
        {
            i = i + cNoticeMapper.delete(noticeId);
        }
        return i;
    }
}